import { defineStore } from 'pinia'
import { ref } from 'vue';
import { LoginData } from '../service/administrator/type';
import { login as checkLogin } from '../service/administrator/administrator';
import { ElMessage } from 'element-plus'
//组合式api写法

export const useUserStore = defineStore("userstore", () => {

   

    const token = ref("");
    const menus = ref<any>();
 
    const login= (data:LoginData)=>{

        return new Promise(async(resolve,reject)=>{
            const res:any=await checkLogin(data);
            if(res.errCode===10000){
          
                token.value=  res.data.token;
                menus.value=   res.data.menu;
                resolve(res.data);
                
            }
            else{
                reject(res);
            }
            
        })
       
    }

    return {
        token, menus,login
    }


},{
    persist:{
        storage:sessionStorage
    }
})